//package cn.net.shuxing.yifu.common.quartz.config;
//
//import cn.net.shuxing.yifu.common.quartz.job.CoinGrantJob;
//import cn.net.shuxing.yifu.common.quartz.job.CoinGrantSimpleJob;
//import cn.net.shuxing.yifu.common.quartz.job.DealMatchJob;
//import cn.net.shuxing.yifu.common.quartz.job.TestJob;
//import cn.net.shuxing.yifu.common.service.DealMatchService;
//import cn.net.shuxing.yifu.common.service.ShareholderCommonService;
//import cn.net.shuxing.yifu.common.util.JedisUtil;
//import cn.net.shuxing.yifu.common.util.LocalDateTimeUtil;
//import cn.net.shuxing.yifu.common.util.RedisKeyCreator;
//import com.alibaba.fastjson.JSON;
//import org.quartz.*;
//import org.quartz.impl.StdSchedulerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Lazy;
//import redis.clients.jedis.Jedis;
//
//import java.time.LocalDateTime;
//import java.time.ZoneId;
//import java.time.ZonedDateTime;
//import java.util.Date;
//
//@Configuration
//public class QuartzConfiguration {
//
//    @Autowired
//    private DealMatchService dealMatchService;
//
//    @Autowired
//    private ShareholderCommonService shareholderCommonService;
//
//    @Autowired
//    private JedisUtil jedisUtil;
//
//    @Autowired
//    private Scheduler scheduler;
//
//    @Autowired
//    private JobDetail coinGrantJobCronDetail;
//
//    @Bean
//    public JobDetail testJobDetail(){
//        return JobBuilder.newJob(TestJob.class)//PrintTimeJob我们的业务类
//                .withIdentity("TestJob")//可以给该JobDetail起一个id
//                //每个JobDetail内都有一个Map，包含了关联到这个Job的数据，在Job类中可以通过context获取
//                .storeDurably()//即使没有Trigger关联时，也不需要删除该JobDetail
//                .build();
//    }
//
//
//
//    @Bean
//    public Trigger testJobTrigger() {
//        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("* * * * * ?");
//        return TriggerBuilder.newTrigger()
//                .forJob(testJobDetail())//关联上述的JobDetail
//                .withIdentity("quartzService")//给Trigger起个名字
//                .withSchedule(cronScheduleBuilder)
//                .build();
//    }
//
//    @Bean
//    public JobDetail dealMatchJobDetail()
//    {
//        return JobBuilder.newJob(DealMatchJob.class)
//                .withIdentity("DealMatchJob")
//                .usingJobData("dealMatchServiceJson",JSON.toJSONString(dealMatchService))
//                .storeDurably()
//                .build();
//    }
//
//    @Bean
//    public Trigger dealMatchJobTrigger() {
//        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("* * * * * ?");
//        return TriggerBuilder.newTrigger()
//                .forJob(dealMatchJobDetail())//关联上述的JobDetail
//                .withIdentity("dealMatchJobTrigger")//给Trigger起个名字
//                .withSchedule(cronScheduleBuilder)
//                .build();
//    }
//
//    @Bean
//    public JobDetail coinGrantJobCronDetail()
//    {
//        return JobBuilder.newJob(CoinGrantJob.class)
//                .withIdentity("coinGrantJobCronDetail")
//                .usingJobData("shareholderCommonServiceJson",JSON.toJSONString(shareholderCommonService))
//                .storeDurably()
//                .build();
//    }
//
//    @Bean
//    @Lazy(value = true)
//    public Trigger coinGrantJobCronTrigger() {
//        //Jedis //jedis = jedisUtil.getJedis();
//        String grantIntervalTime = jedisUtil.get(RedisKeyCreator.grantIntervalTime());
//        CronScheduleBuilder coinGrantJobCronTrigger = CronScheduleBuilder.cronSchedule(grantIntervalTime);
//        return TriggerBuilder.newTrigger()
//                .forJob(coinGrantJobCronDetail())//关联上述的JobDetail
//                .withIdentity("coinGrantJobCronTrigger")//给Trigger起个名字
//                .withSchedule(coinGrantJobCronTrigger)
//                .build();
//    }
//
//    @Bean
//    @Lazy
//    public JobDetail coinGrantSimpleJobDetail(@Autowired Trigger coinGrantJobCronTrigger)
//    {
//        JobDataMap jobDataMap = new JobDataMap();
//        jobDataMap.put("scheduleJson",JSON.toJSONString(scheduler));
//        jobDataMap.put("schedulerClassName",scheduler.getClass());
//        jobDataMap.put("coinGrantJobCronDetailJson",JSON.toJSONString(coinGrantJobCronDetail));
//        jobDataMap.put("coinGrantJobCronDetailClassName",coinGrantJobCronDetail.getClass());
//        jobDataMap.put("coinGrantJobCronTriggerJson",JSON.toJSONString(coinGrantJobCronTrigger));
//        jobDataMap.put("coinGrantJobCronTriggerClassName",coinGrantJobCronTrigger.getClass());
//
//        return JobBuilder.newJob(CoinGrantSimpleJob.class)
//                .withIdentity("coinGrantSimpleJobDetail")
//                .usingJobData(jobDataMap)
//                .storeDurably()
//                .build();
//    }
//
//    @Bean
//    @Lazy
//    public Trigger coinGrantJobSimpleTrigger() {
//        SimpleScheduleBuilder coinGrantJobSimpleTrigger = SimpleScheduleBuilder.simpleSchedule();
//
//        /** 获取开始配发时间 **/
//        //Jedis //jedis = jedisUtil.getJedis();
//        LocalDateTime startGrantTime = LocalDateTime.parse(jedisUtil.get(RedisKeyCreator.startGrantTime()));
//        //jedisUtil.close();
//        Date startGrantTime1 = LocalDateTimeUtil.toDate(startGrantTime);
//
//        /** 构造Trigger **/
//        return TriggerBuilder.newTrigger()
//                .forJob(coinGrantJobCronDetail())//关联上述的JobDetail
//                .withIdentity("coinGrantJobSimpleTrigger")//给Trigger起个名字
//                .withSchedule(coinGrantJobSimpleTrigger)
//                .startAt(startGrantTime1)
//                .build();
//    }
//
//
//
//
//}